package com.web.productservice.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.web.productservice.entity.Product;
import com.web.productservice.service.ProductService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.swing.text.BadLocationException;

@RestController
public class ProductController {
    @Resource
    private ProductService productService;

    @RequestMapping("/product/{id}")
    @SentinelResource(value = "product/{id}", blockHandler = "findProductByIdBlockException",blockHandlerClass = ExceptionHandle.class)
    public ResponseEntity<Product> findProductById(@PathVariable Integer id) {
        Product product = productService.getById(id);
        return ResponseEntity.ok(product);
    }


}